package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.LawCase;
import com.ruoyi.business.service.ILawCaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * caseController
 * 
 * @author lwj
 * @date 2021-05-22
 */
@RestController
@RequestMapping("/business/case")
public class LawCaseController extends BaseController
{
    @Autowired
    private ILawCaseService lawCaseService;

    /**
     * 查询case列表
     */
//    @PreAuthorize("@ss.hasPermi('business:case:list')")
    @GetMapping("/list")
    public TableDataInfo list(LawCase lawCase)
    {
        startPage();
        List<LawCase> list = lawCaseService.selectLawCaseList(lawCase);
        return getDataTable(list);
    }

    /**
     * 导出case列表
     */
    @PreAuthorize("@ss.hasPermi('business:case:export')")
    @Log(title = "case", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LawCase lawCase)
    {
        List<LawCase> list = lawCaseService.selectLawCaseList(lawCase);
        ExcelUtil<LawCase> util = new ExcelUtil<LawCase>(LawCase.class);
        return util.exportExcel(list, "case");
    }

    /**
     * 获取case详细信息
     */
//    @PreAuthorize("@ss.hasPermi('business:case:query')")
    @GetMapping(value = "/{caseId}")
    public AjaxResult getInfo(@PathVariable("caseId") Integer caseId)
    {
        return AjaxResult.success(lawCaseService.selectLawCaseById(caseId));
    }

    /**
     * 新增case
     */
    @PreAuthorize("@ss.hasPermi('business:case:add')")
    @Log(title = "case", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LawCase lawCase)
    {
        return toAjax(lawCaseService.insertLawCase(lawCase));
    }

    /**
     * 修改case
     */
    @PreAuthorize("@ss.hasPermi('business:case:edit')")
    @Log(title = "case", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LawCase lawCase)
    {
        return toAjax(lawCaseService.updateLawCase(lawCase));
    }

    /**
     * 删除case
     */
    @PreAuthorize("@ss.hasPermi('business:case:remove')")
    @Log(title = "case", businessType = BusinessType.DELETE)
	@DeleteMapping("/{caseIds}")
    public AjaxResult remove(@PathVariable Integer[] caseIds)
    {
        return toAjax(lawCaseService.deleteLawCaseByIds(caseIds));
    }
}
